package com.tmt.im.wallet.service;

import com.tmt.data.jpa.service.TmtJpaDataService;
import com.tmt.im.jpa.entity.SystemParam;
import com.tmt.im.jpa.repository.SystemParamRepo;
import com.tmt.im.jpa.systemparam.SystemParamInitiator;
import com.tmt.im.wallet.config.beans.ClientInfoProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/9/20 16:09
 * @Version 1.0
 **/
@Service
@Slf4j
@Order(0)
public class SystemParamService extends TmtJpaDataService<SystemParam, Long> {

    private final ClientInfoProperties clientInfoProperties;

    private final SystemParamRepo systemParamRepo;


    public SystemParamService(ClientInfoProperties clientInfoProperties,
                              SystemParamRepo mainRepo) {
        super(mainRepo);
        this.clientInfoProperties = clientInfoProperties;
        this.systemParamRepo = mainRepo;
    }

    @Transactional(rollbackFor = Exception.class)
    public void InitializeTable() {
        try {
            log.info("----初始化系统参数----开始---");
            SystemParamInitiator.initial(clientInfoProperties, systemParamRepo);
            log.info("----初始化系统参数----结束---");
        } catch (Exception ex) {
            log.debug(ex.getMessage(), ex);
        }
    }
}
